<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>工程案例</title>
    <script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="/static/ueditor/lang/zh-cn/zh-cn.js"></script>
    <!-- <link rel="stylesheet" href="/static/layui-v2.6.8/layui/css/layui.css"> -->
    <link rel="stylesheet" href="/static/layuiAdmin.std-v1.7.1/src/layuiadmin/layui/css/layui.css">
    <script src="/static/layuiAdmin.std-v1.7.1/src/layuiadmin/layui/layui.js"></script>
    <style>
        .layui-form-selected dl {
            z-index: 1000;
        }
    </style>
</head>

<body>
    <?php
    include "../../fun.php";
    $db=conndb();
    isLogin();
    ?>
    <div style="padding-top:10px">
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">类别</label>
                <div class="layui-input-block" style="width:200px">
                    <?php echo select_trees(8, $db, 0, "sortid") ?>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block" style="width:500px">
                    <input type="text" name="cases_name" required lay-verify="required" placeholder="请输入标题"
                        autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图片</label>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" id="pic">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                    <!-- 存放图片名称 -->
                    <input type="hidden" name="pic">
                    <!-- 展示图片 -->
                    <!-- 设置img的样式 -->
                    <style>
                        img {
                            max-width: 100px;
                        }
                    </style>
                    <div id="picInfo" style="display:inline-block"></div>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">内容</label>
                <div class="layui-input-block">
                    <script id="editor" name="content" type="text/plain" style="width:1024px;height:500px;"></script>
                    <script>
                        UE.getEditor('editor');
                    </script>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">添加时间</label>
                <div class="layui-input-block" style="width:500px">
                    <!-- date("Y-m-d H:i:s") 获取当前时间并格式化 -->
                    <input type="text" class="layui-input" name="time" id="time"
                        value="<?php echo date("Y-m-d H:i:s"); ?>">
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit"
                    value="确认添加">
                <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit"
                    value="确认编辑">
            </div>
        </form>
    </div>

    <!-- <script>
        layui.use(['form', 'upload', 'jquery', 'laydate'], function() {
            var form = layui.form //表单提交
                ,
                upload = layui.upload //文件上传
                ,
                $ = layui.jquery,
                laydate = layui.laydate; //时间日期组件

            //监听提交
            form.on('submit(formDemo)', function(data) {
                // layer.msg(JSON.stringify(data.field));
                $.ajax({
                    method: "post",
                    url: "./save.php",
                    data: data.field,
                    dataType: "json",
                    success: function(res) {
                        if (res.code == 0) {
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 2000
                            }, function() {
                                parent.location.href = './index.php';
                            })
                        }
                    }
                });
                return false;
            });

            //执行文件上传实例
            var uploadInst = upload.render({
                elem: '#pic' //绑定元素
                    ,
                url: '../upload.php' //上传接口
                    ,
                done: function(res) {
                    //上传完毕回调
                    if (res.code == 0) {
                        $("input[name='pic']").val(res.pic);
                        var html = `<img src="/admin/upload/${res.pic}" alt="">`;
                        $("#picInfo").html(html);
                    }
                },
                error: function() {
                    //请求异常回调
                }
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#time' //指定元素
                    ,
                type: 'datetime' //日期时间   年月日时分秒
                // ,type: 'time'//时间   时分秒 
                // ,type: 'date'//日期时间   年月日 默认
            });
        });
    </script> -->
    <script>
        layui.use(['form','upload','laydate'],function (){
            var $=layui.$
            ,form=layui.form
            ,upload=layui.upload
            ,laydate=layui.laydate;


            // 监听事件
            form.on('submit(layuiadmin-app-form-submit)', function (data) {
                var field=data.field;//获取提交的字段
                var index=parent.layer.getFrameIndex(window.name);//得到当前iframe的索引

                //提交ajax成功后，关闭当前弹层并重载表格
                $.ajax({
                    type: "post",
                    url: "./save.php",
                    data: field,
                    dataType: "json",
                });
                parent.layui.table.reload('LAY-app-content-list'); //重载表格
                parent.layer.close(index);//关闭弹层
            });


            // 图片上传
            upload.render({
                elem: '#pic',
                url: '../upload.php',
                accept: 'images', //指定允许上传时校验的文件类型为图片
                // acceptMime规定打开文件选择框时，筛选出的文件类型，值为用逗号隔开的 MIME 类型列表
                acceptMime: 'image/*', //（只显示图片文件）
                // method: ''  //可选项。HTTP类型，默认post
                done: function(res) {
                    //上传完毕回调
                    if (res.code == 0) {
                        $("input[name='pic']").val(res.pic);
                        var html = `<img src="/admin/upload/${res.pic}" alt="">`;
                        $("#picInfo").html(html);
                    }
                },
                error: function() {
                    //请求异常回调
                }
            })

            //执行一个laydate实例
            laydate.render({
                elem: '#time' //指定元素
                    ,
                type: 'datetime' //日期时间   年月日时分秒
                // ,type: 'time'//时间   时分秒 
                // ,type: 'date'//日期时间   年月日 默认
            });
        })

        
    </script>

</body>

</html>